package views
{
	import com.greensock.TweenMax;
	
	import flash.text.TextFieldAutoSize;
	
	import fr.chrysalis.ui.UI;
	import fr.chrysalis.ui.assets.Asset;
	import fr.chrysalis.ui.assets.IAsset;
	import fr.chrysalis.ui.assets.SWFAsset;
	import fr.chrysalis.ui.components.core.ContainerScrollable;
	import fr.chrysalis.ui.components.core.Form;
	import fr.chrysalis.ui.components.core.Style;
	import fr.chrysalis.ui.components.display.Button;
	import fr.chrysalis.ui.components.display.Label;
	import fr.chrysalis.ui.components.display.Text;
	import fr.chrysalis.ui.components.events.FormEvent;
	import fr.chrysalis.ui.components.input.InputText;
	import fr.chrysalis.ui.styles.Align;
	import fr.chrysalis.utils.Debug;
	
	public class Connexion extends ContainerScrollable
	{
		
		public var form:Form;
		private var submitBtn:Button;
		
		public function Connexion()
		{
			
			super(new Asset());
			
			this.width = 390;
			this.height = 230;
			
			this.form = new Form(new SWFAsset(UI.get('bg1')));
			this.form.x = 0;
			this.form.y = 0;
			this.form.selfAlign = Align.TOP_LEFT;
			
			this.form.addEventListener(FormEvent.SUBMIT, submitForm);
			
			var labelNom:Text = new Text(new Asset());
			labelNom.text = 'Name :';		
			labelNom.x = 150-2;
			labelNom.setStyle(Style.get('calibri_12'));
			labelNom.selfAlign = Align.TOP_RIGHT;
			
			var nom:InputText = new InputText( new SWFAsset(UI.get('inputText')) );
			nom.name = 'nom';
			nom.value = '';
			nom.x = 150+2;
			nom.y = 30;
			nom.setStyle(Style.get('calibri_12_grey'));
			nom.selfAlign = Align.TOP_LEFT;
			
			labelNom.y = nom.y + (nom.height / 2) - (labelNom.height / 2);
			
			this.form.addChild(labelNom);
			this.form.addField(nom);
			
			var labelId:Text = new Text(new Asset());
			labelId.text = 'Id du player :';
			labelId.x = 150-2;
			labelId.setStyle(Style.get('arial_12'));
			labelId.selfAlign = Align.TOP_RIGHT;
			
			var id:InputText = new InputText( new SWFAsset(UI.get('inputText')) );
			id.name = 'id';
			id.value = '';
			id.x = 150+2;
			id.y = 80;
			id.setStyle(Style.get('arial_12_grey'));
			id.selfAlign = Align.TOP_LEFT;
			
			labelId.y = id.y + (id.height / 2) - (labelId.height / 2);
			
			this.form.addChild(labelId);
			this.form.addField(id);
			
			this.submitBtn = new Button( new SWFAsset(UI.get('button')) );
			this.submitBtn.text = 'Valider';
			this.submitBtn.x = 150+30;
			this.submitBtn.y = 150;
			this.submitBtn.selfAlign = Align.MIDDLE_CENTER;
			
			this.form.addSubmit(this.submitBtn);
			
			var lorem:Text = new Text(new Asset());
			lorem.getTextField().width = 340;
			lorem.text = ( [
				"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas dictum cursus consectetur. In hac habitasse platea dictumst. Sed blandit porta tellus nec ornare. Ut a urna est, in consectetur nunc. Pellentesque dapibus molestie erat nec pellentesque. Nam aliquam augue id urna pharetra ut iaculis lacus imperdiet. Aenean ut tortor sapien. Suspendisse rhoncus ipsum at magna ullamcorper eleifend. Etiam luctus pharetra blandit. Nam quis diam orci, eget sodales lacus. Donec sodales urna at nulla faucibus pharetra. Nulla mollis feugiat odio, vitae euismod libero sollicitudin eget. Donec ultrices, lectus convallis tincidunt dapibus, mi turpis sollicitudin ante, eget commodo quam eros nec odio. In vulputate elementum risus, vel venenatis nisl tristique sed. Nam mattis condimentum dapibus. Phasellus varius auctor elit, a volutpat tellus bibendum eget.",
				"",
				"Praesent ante eros, dignissim eget ullamcorper ut, ultrices ac nulla. Sed sed felis massa, in feugiat urna. Pellentesque pulvinar, augue in egestas ultrices, erat leo feugiat nunc, id iaculis risus justo et neque. Sed id pellentesque urna. Curabitur mollis lobortis laoreet. Nulla aliquet vehicula enim in aliquet. Sed eleifend volutpat sem id mollis.",
				"",
				"Duis condimentum magna in tortor varius fermentum. Praesent sed dui id nisl ornare condimentum non sed nisi. Vestibulum at purus metus, eget mattis est. Maecenas rhoncus consequat laoreet. Proin eleifend bibendum justo vel auctor. Aliquam dictum mattis convallis. Phasellus a quam nec elit dignissim consequat ut eu massa. Nunc cursus libero ut erat mattis cursus eget eget nisi. ",
			] ).join("\n");

			lorem.x = 10;
			lorem.y = 200;
			lorem.setStyle(Style.get('corps_text_12_justify'));
			lorem.selfAlign = Align.TOP_LEFT;
			
			this.form.addChild(lorem);
			this.addChild(this.form);
			
			Debug.dump(this);
			
		}
		
		private function submitForm(evt:FormEvent):void{
			TweenMax.to(this.submitBtn, 0.5, {y:this.submitBtn.y + 20, useFrames: false}); 
		}
		
	}
}